Skip to content

Fix #4390: Sort REPL autocomplete suggestions #4417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2018
Merged

Fix #4390: Sort REPL autocomplete suggestions #4417

merged 4 commits into from
May 1, 2018

Conversation

ankitson
Copy link
Contributor

This seems to be a quick fix for #4390. Its my first PR to dotty so I might be missing something.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case to dotty.tools.repl.TabcompleteTests. Something like:

  @Test def sortedCompletions =
    fromInitialState { implicit state =>
      compiler
        .compile("class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }")
        .stateOrFail
    }
    .andThen { implicit state =>
      val expected = List("comp1", "comp2", "comp3")
      assertEquals(expected, tabComplete("(new Foo).comp").suggestions)
    }

@@ -219,7 +219,7 @@ object Interactive {
case _ => getScopeCompletions(ctx)
}
interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %")
(completionPos, completions.toList)
(completionPos, completions.toList.sortBy(_.name.show))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use _.name.toString

@ankitson
Copy link
Contributor Author

Done!


@Test def sortedCompletions: Unit =
fromInitialState { implicit state =>
val src = """class Foo { def comp1 = 1; def compa = 3; def compA = 4 }"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use simple quotes. Triple quotes are not needed here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the code snippet I gave you. I think the ordering is clearer:

class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }
val expected = List("comp1", "comp2", "comp3")

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @ankitson 🎉

@@ -219,7 +219,7 @@ object Interactive {
case _ => getScopeCompletions(ctx)
}
interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %")
(completionPos, completions.toList)
(completionPos, completions.toList.sortBy(_.name.toString))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarter We have an ordering for Name that differs from the default String ordering. I am wondering if we should use it here? The Name ordering will not group type names and term names together

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they should be grouped together, but we should also not display type completions if we're not in a type context

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but that's probably out of the scope of this PR

@scala scala deleted a comment from smarter May 1, 2018
@allanrenucci allanrenucci merged commit cdbb1be into scala:master May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants